#include <iostream>
using namespace std;

// demo1: declare value
namespace exercise
{
    int iVal = 100;
    double dVal = 200.0;
    const int limit = 1000;
} // namespace exercise

int iVal = -10; // global iVal

using exercise::dVal;
// using exercise::iVal; // error duplicate
using exercise::limit;

// demo2: matched func
namespace primerLib
{
    void cmp();
    void cmp(const void *);
} // namespace primerLib
using primerLib::cmp;
void cmp(int);
void cmp(double, double a = 2.1);
void cmp(char *, char *a = "abc");

void use_cmp()
{
    cmp(0); // matched with cmp(int)
    /* but if we use like that it will see our namespace's cmp
    ** -- code::cpp
    **    using primerLib::cmp;
    **    cmp(0);
    ** BECAUSE our namespace is in the func field and it will just search cmp in the func field.
    */
}

int main()
{
    using namespace exercise;
    int iVal = 10;
    double dVal = 20.0;
    int sum = iVal + limit;
    sum += dVal + exercise::dVal;
    ++iVal;   // local scope
    ++::iVal; // :: is scope resolution operator
    cout << "iVal: " << iVal << endl;
    cout << "::iVal: " << ::iVal << endl;
}
